package com.modelscope.ai.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.modelscope.ai.domain.dto.ArticleItemQueryCriteria;
import com.modelscope.ai.domain.dto.ArticleQueryCriteria;
import com.modelscope.ai.domain.dto.DikeQueryCriteria;
import com.modelscope.ai.domain.entity.Article;
import com.modelscope.ai.domain.entity.ArticleItem;
import com.modelscope.ai.domain.entity.Dike;
import com.modelscope.ai.domain.entity.R;
import com.modelscope.ai.service.ArticleItemService;
import com.modelscope.ai.service.ArticleService;
import com.modelscope.ai.service.DikeService;
import com.modelscope.ai.service.SubscribeArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Collections;
import java.util.List;

// @Tag	用在controller类上，描述此controller的信息
//@Operation	用在controller的方法里，描述此api的信息
//@Parameter	用在controller方法里的参数上，描述参数信息
//@Parameters	用在controller方法里的参数上
//@Schema	用于Entity，以及Entity的属性上
//@ApiResponse	用在controller方法的返回值上
//@ApiResponses	用在controller方法的返回值上
//@Hidden	用在各种地方，用于隐藏其api
//————————————————
@RequiredArgsConstructor
@Slf4j
@Validated
@RestController
@RequestMapping("/article")
@Tag(name = "article", description = "文章")
public class ArticleController {

    private final ArticleService articleService;
    private final ArticleItemService articleItemService;


    /**
     * 根据条件查询用户信息
     *
     * @param criteria
     * @return
     */
    @Operation(summary = "批量获取合集信息", description = "批量获取用户信息，用于页面展示")
    @PostMapping("/list")
    public R<Page<Article>> queryArticleAll(@Valid @RequestBody ArticleQueryCriteria criteria) {
        return R.ok(articleService.queryAll(criteria));
    }


    @Operation(summary = "根据id获取文章", description = "批量获取用户信息，用于页面展示")
    @PostMapping("/byId")
    public R<Article> queryArticleById(@RequestBody ArticleQueryCriteria criteria) {
        return R.ok(articleService.getById(criteria.getUid()));
    }

    @Operation(summary = "批量获取文章信息", description = "批量获取用户信息，用于页面展示")
    @PostMapping("/item/list")
    public R<List<ArticleItem>> queryArticleItemAll(@Valid @RequestBody ArticleItemQueryCriteria criteria) {
        return R.ok(articleItemService.queryAll(criteria));
    }

    @PostMapping("/add")
    public R<String> addArticle(@RequestBody Article add) {
        articleService.addArticle(add);
        return R.ok("添加成功");
    }

    @PostMapping("/item/add")
    public R<String> addArticleItem(@RequestBody ArticleItem criteria) {
        articleItemService.addArticleItem(criteria);
        return R.ok("添加成功");
    }

    @PutMapping("/update")
    public R<String> updateArticle(@RequestBody Article criteria) {
        log.info("修改article:{}", criteria);
        articleService.updateArticle(criteria);
        return R.ok("修改成功");
    }

    @PutMapping("/item/pdate")
    public R<String> updateArticleItem(@RequestBody ArticleItem criteria) {
        articleItemService.updateArticleItem(criteria);
        return R.ok("修改成功");
    }


    // 删除用户信息
    @DeleteMapping("/delete")
    public R<String> deleteArticle(Long uid) {
        log.info("删除id" + uid);
        articleService.deleteArticle(Collections.singletonList(uid));
        return R.ok("删除成功");
    }

    @DeleteMapping("/item/delete")
    public R<String> deleteArticleItem(Long uid) {
        log.info("删除id" + uid);
        articleItemService.deleteArticleItem(Collections.singletonList(uid));
        return R.ok("删除成功");
    }


}
